/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RegistroNuevoProducto.java
 *
 * Created on 14-abr-2012, 23:55:09
 */

package gui;


import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
import modelo.Bebida;
import modelo.Comida;
import modelo.Restaurante;

/**
 *
 * @author Lenovo
 */
public class RegistroNuevoProducto extends javax.swing.JFrame {

    private Restaurante miRestaurante;
    public RegistroNuevoProducto(Restaurante restaurante) {
        initComponents();
        miRestaurante= restaurante;
        this.setLocationRelativeTo(null);
    }
    
  

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPInfoProducto = new javax.swing.JPanel();
        jLNombre = new javax.swing.JLabel();
        jLPrecio = new javax.swing.JLabel();
        jLTipo = new javax.swing.JLabel();
        jTFNombre = new javax.swing.JTextField();
        jTFPrecio = new javax.swing.JTextField();
        jCBTipo = new javax.swing.JComboBox();
        jBCancelarRegistroPedido = new javax.swing.JButton();
        jBRegistrarProducto = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Restaurante \"Con Sabor\" - Registro de productos nuevos");

        jPInfoProducto.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Información del nuevo producto", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 14), new java.awt.Color(204, 0, 102))); // NOI18N

        jLNombre.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLNombre.setForeground(new java.awt.Color(153, 0, 51));
        jLNombre.setText("Nombre: ");

        jLPrecio.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLPrecio.setForeground(new java.awt.Color(153, 0, 51));
        jLPrecio.setText("Precio: ");

        jLTipo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLTipo.setForeground(new java.awt.Color(153, 0, 51));
        jLTipo.setText("Tipo:");

        jTFPrecio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTFPrecioKeyTyped(evt);
            }
        });

        jCBTipo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jCBTipo.setForeground(new java.awt.Color(153, 0, 51));
        jCBTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tipo de producto", "Bebida", "Entrada", "Plato Fuerte", "Postre" }));

        javax.swing.GroupLayout jPInfoProductoLayout = new javax.swing.GroupLayout(jPInfoProducto);
        jPInfoProducto.setLayout(jPInfoProductoLayout);
        jPInfoProductoLayout.setHorizontalGroup(
            jPInfoProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPInfoProductoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPInfoProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLNombre)
                    .addComponent(jLPrecio))
                .addGap(26, 26, 26)
                .addGroup(jPInfoProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPInfoProductoLayout.createSequentialGroup()
                        .addComponent(jTFPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(92, 92, 92)
                        .addComponent(jLTipo)
                        .addGap(18, 18, 18)
                        .addComponent(jCBTipo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jTFNombre))
                .addContainerGap())
        );
        jPInfoProductoLayout.setVerticalGroup(
            jPInfoProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPInfoProductoLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPInfoProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLNombre)
                    .addComponent(jTFNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPInfoProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLPrecio)
                    .addComponent(jTFPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCBTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLTipo))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jBCancelarRegistroPedido.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBCancelarRegistroPedido.setForeground(new java.awt.Color(204, 0, 102));
        jBCancelarRegistroPedido.setText("CANCELAR EL REGISTRO ACTUAL");
        jBCancelarRegistroPedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarRegistroPedidoActionPerformed(evt);
            }
        });

        jBRegistrarProducto.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBRegistrarProducto.setForeground(new java.awt.Color(204, 0, 102));
        jBRegistrarProducto.setText("REGISTRAR PRODUCTO");
        jBRegistrarProducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBRegistrarProductoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jBRegistrarProducto)
                        .addGap(47, 47, 47)
                        .addComponent(jBCancelarRegistroPedido))
                    .addComponent(jPInfoProducto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jPInfoProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBCancelarRegistroPedido)
                    .addComponent(jBRegistrarProducto))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBRegistrarProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBRegistrarProductoActionPerformed
   String nombre= jTFNombre.getText();
   double precio= Double.parseDouble(jTFPrecio.getText());
   if(jCBTipo.getSelectedIndex()==0){
       JOptionPane.showMessageDialog(null, "porfavor elija un tipo de comida");
   }else {
       if(jCBTipo.getSelectedIndex()==1){
           String msj=miRestaurante.registrarNuevoProducto(new Bebida(nombre, precio));
           JOptionPane.showMessageDialog(null, msj);
           limpiarCampos();
       }else{
          String msj =miRestaurante.registrarNuevoProducto(new Comida(nombre, precio,(String)jCBTipo.getSelectedItem()));
           JOptionPane.showMessageDialog(null, msj);
           limpiarCampos();
       }
   }
}//GEN-LAST:event_jBRegistrarProductoActionPerformed

    private void jBCancelarRegistroPedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarRegistroPedidoActionPerformed
    limpiarCampos();
    }//GEN-LAST:event_jBCancelarRegistroPedidoActionPerformed

    /**
     * este campo solo recibe numeros por ser el precio
     * @param evt 
     */
    private void jTFPrecioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTFPrecioKeyTyped
         if(!Character.isDigit((char)evt.getKeyChar()))
        {
            evt.setKeyChar((char) KeyEvent.VK_CLEAR);
            JOptionPane.showMessageDialog(null, "El precio solo se da en valor numerico");
        }
    }//GEN-LAST:event_jTFPrecioKeyTyped

    /**
     * metodo que limpia los campos de texto de la ventana
     * registrar nuevo producto
     */
    public void limpiarCampos(){
        jTFNombre.setText(null);
        jTFPrecio.setText(null);
        jCBTipo.setSelectedIndex(0);
    }
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCancelarRegistroPedido;
    private javax.swing.JButton jBRegistrarProducto;
    private javax.swing.JComboBox jCBTipo;
    private javax.swing.JLabel jLNombre;
    private javax.swing.JLabel jLPrecio;
    private javax.swing.JLabel jLTipo;
    private javax.swing.JPanel jPInfoProducto;
    private javax.swing.JTextField jTFNombre;
    private javax.swing.JTextField jTFPrecio;
    // End of variables declaration//GEN-END:variables

}
